﻿<!--#include file="../Inc/easp/easp.asp"-->
<!--#include file="../Inc/conn1.asp"-->
<!--#include file="../inc/checklogin.asp"-->
<!--#include file="../inc/easyide.asp"-->
<% CheckLogin("index.asp") %>
<%
	If Session("Authority")<>"0" Then
		Response.Write "<script type=""text/javascript"">top.location.href='../main.asp';</script>"
	end if				
%>
<%
  dim password,password1,uid,authority,szSelect,selectArr,gid
  uid = Trim(Request.Form("uid"))'用户ID
  password = Trim(Request.Form("password"))
  authority = Trim(Request.Form("radio"))'权限
  gid = Trim(Request.Form("GroupList"))'组ID
  szSelect  = Trim(Request.Form("CountryList"))
  selectArr = Split(szSelect, ",")'选中的国家ID 
     
  if uid = "" Then
  	Response.Write "<script type=""text/javascript"">window.history.back(-1);</script>"
  end if
    
  '修改用户权限，和管理的组
  dim result1
  if password <> "" then
    result1 = Easp.db.UpdateRecord("user", "ID=" & uid & "", Array("g_id:" & gid & "", "PassWord:" & password & "", "Authority:" & authority & ""))
  else
  	result1 = Easp.db.UpdateRecord("user", "ID=" & uid & "", Array("g_id:" & gid & "", "Authority:" & authority & ""))
  end if
  if result1<>0 then
  else
  	Response.Write "<script type=""text/javascript"">alert('Alter User Failed!');top.location.href='index.asp';</script>"
  end if
  
  '清除该用户管理的所有国家
  dim result2  
  result2 = Easp.db.Exec("delete from userCountry where UserID=" & uid & "")  
  if result2<>0 then
  else
  	die "Error2"
  	Response.Write "<script type=""text/javascript"">alert('Alter User Failed!');top.location.href='index.asp';</script>"
  end if
  
  '修改用户管理的国家
  if szSelect<>"" then
  	dim i
    for i = 0 to ubound(selectArr)      
      call Easp.db.Exec("insert into UserCountry(UserID, CountryID) values(" & uid & "," & selectArr(i) & ")")
    next
  end if

  Response.Write "<script type=""text/javascript"">alert('Successfully Alter User!');top.location.href='index.asp';</script>"
%>